
#include "main.h"
#include "list.h"
add Stu_data[50] =
    {
        {.name = "刘备", .sex = "男", .age = 18, .id = 1},
        {.name = "关羽", .sex = "男", .age = 18, .id = 2},
        {.name = "张飞", .sex = "女", .age = 18, .id = 3},
        {.name = "诸葛", .sex = "男", .age = 18, .id = 4},
        {.name = "赵云", .sex = "男", .age = 18, .id = 5},
        {.name = "马超", .sex = "男", .age = 18, .id = 6},
        {.name = "祝融", .sex = "女", .age = 18, .id = 7},
        {.name = "小乔", .sex = "女", .age = 18, .id = 8},
        {.name = "大乔", .sex = "女", .age = 18, .id = 9},
        {.name = "貂蝉", .sex = "女", .age = 18, .id = 10}};

add Stu =

    {.name = "刘禅", .sex = "男", .age = 18, .id = 11};
add stu =

    {.name = "马云", .sex = "男", .age = 18, .id = 0};

void test()
{
    Link_list *head = init_link_list(); // 这个函数是创建函数,里面没有问题
    Node *L = (Node *)malloc(sizeof(Node));
    head->head = NULL;
    L->next = NULL; // 初始化L的next为NULL

    // 创建链表并添加数据
    for (int i = 0; i < 10; i++)
    {
        Node *newNode = (Node *)malloc(sizeof(Node)); // 创建新节点
        newNode->data = Stu_data[i];                  // 赋值数据
        newNode->next = NULL;                         // 新节点的next初始化为NULL

        if (head->head == NULL)
        {
            // 如果链表为空，将新节点设为头节点
            head->head = newNode;
        }
        else
        {
            // 找到链表的最后一个节点
            L->next = newNode; // 将上一个节点的next指向新节点
        }
        L = newNode; // 更新L为新节点
    }

    Node *head_Node = head->head;
    print_link_list(head_Node);
    printf("=============================================================================1中插\n");
    insert_node(head_Node, Stu, 5); // 中间插入
    print_link_list(head_Node);
    printf("=============================================================================2中删\n");
    delete_node(head_Node, 5); // 中间删除
    print_link_list(head_Node);
    printf("=============================================================================3尾插\n");
    Inser_node(head_Node, Stu); // 尾插
    print_link_list(head_Node);
    printf("=============================================================================4尾删\n");
    Delete_node(head_Node); // 尾删
    print_link_list(head_Node);
    printf("=============================================================================5头插\n");
    head_Inser_node(&head_Node, stu); // 头插
    print_link_list(head_Node);
    printf("=============================================================================6头删\n");
    head_Delete_node(&head_Node);
    print_link_list(head_Node);
    free_link_list(&head_Node); // 销毁
    print_link_list(head_Node);
}

int main(int argc, char const *argv[])
{
    test();
    return 0;
}
